<template>
    <view-box v-if="addBasic" style="background:#F3F6F7;">
      <div style="height:10px;"></div>
      <div class="border-oui">
        <x-input title="职位名称" v-model="addBasic.position_name"  placeholder="请输入职位名称" ></x-input>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-input title="职能" v-model="addBasic.zhiwei"   placeholder="请输入职能"></x-input>
      </div>
      <div style="height:10px;"></div>
      <div class="border-oui">
         <popup-picker title="薪资待遇" :data="value6" v-model="addBasic.pay" value-text-align="right"></popup-picker>
         <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
         <x-address title="工作地址" v-model="addressValue" raw-value :list="addressData" @on-shadow-change="onShadowChange" value-text-align="right" ></x-address>
         <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
         <x-input title="详细地址" v-model="addBasic.detailed_address"   placeholder="请输入详细地址"></x-input>
      </div>
      <!-- <div style="height:10px;"></div>
      <div class="border-oui">
        <x-input title="福利" v-model="addBasic.welfare" placeholder="请输入福利"></x-input>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-input title="公司名称" v-model="addBasic.company_name"   placeholder="请输入公司名称"></x-input>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-input title="公司规模" v-model="addBasic.scale"   placeholder="请输入公司规模"></x-input>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-input title="公司性质" v-model="addBasic.nature"   placeholder="请输入公司性质"></x-input>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-input title="公司行业" v-model="addBasic.company_industry"   placeholder="请输入公司行业"></x-input>
      </div> -->
      <div style="height:10px;"></div>
      <div class="border-oui">
        <x-input title="招人数" v-model="addBasic.attract_number"   placeholder="请输入招人数"></x-input>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-input title="联系电话" v-model="addBasic.phone" is-type="china-mobile"  placeholder="联系电话"></x-input>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-input title="工作经验" v-model="addBasic.age_limit" placeholder="请输入经验"></x-input>
      </div>
      <div style="height:10px;"></div>
      <div class="border-oui">
        <p style="width:92%;margin-left:4%;height:40px;line-height:40px;">职位描述</p>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-textarea class="colop" :max="1000" placeholder="职位描述" v-model="addBasic.job_description" :show-counter="false" :height="60" :rows="8" :cols="30"></x-textarea>
      </div>
      <!-- <div style="height:10px;"></div>
      <div class="border-oui">
        <p style="width:92%;margin-left:4%;height:40px;line-height:40px;">公司简介</p>
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <x-textarea class="colop" :max="1000" placeholder="公司简介" v-model="addBasic.company_profile" :show-counter="false" :height="60" :rows="8" :cols="30"></x-textarea>
      </div> -->
        <div style="height:1px;width:92%;margin-left:4%;background:#f4f4f4"></div>
        <!-- <group class="colop" title="公司图片" style="margin-bottom:5px;">
          <input id="uploads" class="width-input"  type="file" style="position: relative; clip:rect(0 0 0 0);margin-left:12px;" accept="image/*" @change="cameraChange" multiple>
        </group> -->
         <div style="height:10px;"></div>
        <group style="margin:0px 3%;">
          <x-button class="back-issue" @click.native="saveup()">发布</x-button>
        </group>
    </view-box>
</template>
<script>
import { ViewBox, Box, XInput, Group, XButton, Datetime, PopupPicker, ChinaAddressData, XHeader, XAddress, CheckIcon, XTextarea } from 'vux'
export default {
  components: {
    ViewBox,
    Box,
    XInput,
    Group,
    XButton,
    Datetime,
    PopupPicker,
    XHeader,
    XAddress,
    CheckIcon,
    XTextarea
  },
  data () {
    return {
      addressData: ChinaAddressData,
      radio001: ['是否统招'],
      value4: '',
      value3: '',
      addxli: [],
      value6: [['薪资面议', '1万-2万', '3万-5万', '5万-7万', '7万-10万', '10万-15万', '15万-20万', '200万-25万', '25万-30万', '30万-50万', '50万-100万']],
      addressValue: [],
      annual_salary: [],
      typec: [],
      value1: '',
      value12: [['在职，暂无跳槽打算', '在职，急寻新工作', '离职，正在找工作', '在职，看看新机会']],
      is_unified: false,
      pid: '',
      id: '',
      tabldata: {
        position_name: '',
        zhiwei: '',
        // company_name: '',
        phone: ''
      },
      company_image: '',
      addBasic: {},
      addiss: {},
      addpid: '',
      demo2: false,
      demo1: true
    }
  },
  computed: {
    disabled () {
      console.log('zunhh')
    },
    userInfo () {
      return this.$store.getters.userInfo
    }
  },
  mounted () {
    if (!this.$store.state.auth.userInfo) {
      this.$store.dispatch('getUserInfo')
    }
    this._getconm()
    this._resetGoodsData()
  },
  created () {
    if (this.$route.query.id !== null) {
      this.id = parseInt(this.$route.query.id)
    }
  },
  methods: {
    cameraChange (event) {
      var file = event.target.files[0]
      var formdata1 = new FormData()
      formdata1.append('file', file, file.name)
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }
      if (file) {
        this.$vux.loading.show()
      }
      this.$http.post(
      '/upload/image',
      formdata1,
      config
      )
      .then(response => {
        // this.upload(response.data.thumb_img)
        this.company_image = response.data.thumb_img
        console.log(response)
        this.$vux.loading.hide()
      })
      .catch(e => {
        this.$vux.loading.hide()
      })
    },
    _resetGoodsData () {
      this.addBasic = Object.assign({}, this.tabldata)
    },
    change () {
      console.log('zhou')
    },
    saveup () {
      if (this.$route.query.id !== undefined) {
        this.updata()
      } else {
        this.save()
      }
    },
    save () {
      // let annualsalarys = String(this.annual_salary)
      console.log(this.addBasic.position_name)
      if (this.addBasic.position_name === '') {
        this.$vux.toast.show({
          text: '职位不能为空',
          type: 'text'
        })
        return false
      }
      if (this.addBasic.zhiwei === '') {
        this.$vux.toast.show({
          text: '职能不能为空',
          type: 'text'
        })
        return false
      }
      if (this.addBasic.phone === '') {
        this.$vux.toast.show({
          text: '联系方式不能为空',
          type: 'text'
        })
        return false
      }
      let nowstatuspay = String(this.addBasic.pay)
      let data = {
        uid: this.userInfo.id ? this.userInfo.id : 0,
        position_name: this.addBasic.position_name,
        pay: nowstatuspay,
        zhiwei: this.addBasic.zhiwei,
        province: this.addiss.province,
        // welfare: this.addBasic.welfare,
        city: this.addiss.city,
        area: this.addiss.area,
        detailed_address: this.addBasic.detailed_address,
        job_description: this.addBasic.job_description,
        attract_number: this.addBasic.attract_number,
        // scale: this.addBasic.scale,
        // nature: this.addBasic.nature,
        // company_industry: this.addBasic.company_industry,
        // company_profile: this.addBasic.company_profile,
        // company_image: this.addBasic.company_image,
        phone: this.addBasic.phone
      }
      this.$http.post('/releasePosition', data).then(response => {
        this.$vux.toast.show({
          text: response.data.message,
          type: 'text'
        })
        this.$router.push({ path: '/PositionPage' })
        console.log(response)
      }).catch(error => {
        console.log(error)
      })
    },
    setDefaults () {
      console.log(1)
    },
    _getconm () {
      this.$http.post('/entrance').then(response => {
        this.pid = response.data.data.id
      })
    },
    onShadowChange (ids, names) {
      this.addiss = {
        province: names[0],
        city: names[1],
        area: names[2]
      }
    }
  }
}
</script>

<style scoped>
    .btn-set-default {
        flex: 1;
        line-height: 50px;
        
    }
    .border-oui{
      width: 92%;
      margin-left: 4%;
      background: #ffffff;
      border-radius: 7px;
    }
    .back-issue{
      background: #32B6C6;
      color: #fff;
    }
</style>
<style>
.colop .weui-cells__title {
    margin-top: 0.77em;
    margin-bottom: 0.3em;
    padding-left: 15px;
    padding-right: 15px;
    color: #000;
    font-size: 16px;
    /* font-size: 16px !important,; */
}
.colop.weui-textarea {
    display: block;
    border: 0;
    resize: none;
    width: 100%;
    color: inherit;
    font-size: 13px;
    line-height: inherit;
    outline: 0;
}
 .weui-cells:before{
        border-top: 0px solid #D9D9D9 !important;
    }
    .weui-cells:after{
        border-bottom: 0px solid #D9D9D9 !important;
    }
    .weui-cell:before {
    border-top: 0px solid #D9D9D9!important;
}
.vux-cell-box:not(:first-child):before {
    border-top: 0px solid #D9D9D9!important;
}
</style>
